<?php
/**
 * User: hufeng
 * Date: 2017/12/13
 * Desc：websocket client
 */
namespace App\Common\Util;

class Task{
    //投递任务
    public function send($param){
        $client = new \Swoole\Client(SWOOLE_SOCK_TCP, SWOOLE_SOCK_ASYNC);
        $client->on("connect", function($cli) use($param) {
            is_array($param) ? $param=json_encode($param) : '';
            $cli->send($param);
        });
        $client->on("receive", function($cli, $data){
            echo 'receive'."\n";
        });
        $client->on("error", function($cli){
            echo 'error'."\n";
        });
        $client->on("close", function($cli){
            echo 'close'."\n";
        });
        $client->connect(TASK_SERVER_IP, TASK_SERVER_PORT, 1);
    }
}